//
//  BuyRecordCell1.m
//  YunGou
//
//  Created by macbook on 16/5/20.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "BuyRecordCell1.h"
#import "YGProgressBarView.h"
#import <UIImageView+WebCache.h>

@interface BuyRecordCell1 ()
@property (weak, nonatomic) IBOutlet UIImageView *thumbImg;
@property (weak, nonatomic) IBOutlet UILabel *goodsName;
@property (weak, nonatomic) IBOutlet UILabel *totalNeed;
@property (weak, nonatomic) IBOutlet UILabel *surplus;
@property (weak, nonatomic) IBOutlet UILabel *goNumber;
@property (weak, nonatomic) IBOutlet YGProgressBarView *progressView;

@end

@implementation BuyRecordCell1

- (void)awakeFromNib {
    // Initialization code
}

- (void)setModel:(ProductModel *)model{
    [_thumbImg sd_setImageWithURL:[NSURL URLWithString:[ImageUrl stringByAppendingString:model.thumb]]];
    [_thumbImg setAccessoryObject:model];
    _thumbImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [_thumbImg addGestureRecognizer:tap];
    _goodsName.text = model.title;
    _totalNeed.text = [NSString stringWithFormat:@"%ld",model.zongrenshu];
    _surplus.text = [NSString stringWithFormat:@"%ld",model.zongrenshu - model.canyurenshu];
    _goNumber.text = model.gonumber;
    _progressView.progress = (double)model.canyurenshu / model.zongrenshu;
}

- (void)handleTap:(UITapGestureRecognizer *)tap{
    ProductModel *model = [tap.view getAccessoryObject];
    if(self.imageBlock){
        self.imageBlock(model);
    }
}


- (IBAction)btnClicked:(UIButton *)sender {
    if (self.buyRecordBlock) {
        self.buyRecordBlock(sender.tag);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
